////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef __WN_SCRIPTING_SCRIPTING_DATA_TYPE_H__
#define __WN_SCRIPTING_SCRIPTING_DATA_TYPE_H__

#include "WNScripting/inc/WNParseNode.h"
#include "WNScripting/inc/WNTypeManager.h"
#include "WNScripting/inc/WNIdentifierMap.h"

namespace WNScripting {
    class WNExpression;

    class WNDataType : public WNParseNode {
    public:
        WNDataType(WN_SIZE_T _startLine,
                   WN_SIZE_T _endLine,
                   WN_SIZE_T _startChar,
                   WN_SIZE_T _endChar,
                   WNVariableType _type);

        WNDataType(WN_SIZE_T _startLine, 
                   WN_SIZE_T _endLine,
                   WN_SIZE_T _startChar,
                   WN_SIZE_T _endChar, 
                   WNIdentifierElement _name);

        WNDataType(WN_SIZE_T _startLine,
                   WN_SIZE_T _endLine,
                   WN_SIZE_T _startChar,
                   WN_SIZE_T _endChar,
                   WNDataType* _subType);

        WNDataType(WN_SIZE_T _startLine,
                   WN_SIZE_T _endLine,
                   WN_SIZE_T _startChar,
                   WN_SIZE_T _endChar,
                   WNDataType* _subType,
                   WNExpression* _arraySize);

        virtual llvm::Value* OptimizeAndGenerate(WNScriptingEngineData& _scriptingData, WNFunctionDecl* _functionDecl);
        virtual llvm::Value* OptimizeAndGenerateArray(WNScriptingEngineData& _scriptingData, WNFunctionDecl* _functionDecl, std::list<WNDataType*>& _optimizationList);

        WNTypeElement GetType();
        WNDataType* GetSubType();
        llvm::Value* GetOptimizedLength();
        WNIdentifierElement GetName();
        const std::list<WNDataType*>* GetSubTypeArray();

    private:
        WNVariableType mType;
        WNIdentifierElement mName;
        WNTypeElement mElementType;
        WNDataType*   mSubType;
        WNExpression* mLength;
        llvm::Value* mLengthVal;
        std::list<WNDataType*> mOptimizationList;
    };
}
#endif // __WN_SCRIPTING_SCRIPTING_DATA_TYPE_H__